﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing.Design;
using System.ComponentModel;
using System.Windows.Forms.Design;
using System.Windows.Forms;
using VsxFactory.Modeling.StrategyManager.Strategies;
using VsxFactory.Modeling.Strategies;

namespace VsxFactory.Modeling.StrategyManager
{
    class CodeGenerationEventEditor : UITypeEditor 
    {
        public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
        {
            return UITypeEditorEditStyle.DropDown;
        }

        public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }
            if (provider == null)
            {
                throw new ArgumentNullException("provider");
            }
            IWindowsFormsEditorService service = provider.GetService(typeof(IWindowsFormsEditorService)) as IWindowsFormsEditorService;
            if (service == null)
            {
                return value;
            }

            CodeGenerationEvent e = (CodeGenerationEvent)value;
            Array enumFields = Enum.GetValues(typeof(CodeGenerationEvent));

            CheckedListBox control = new CheckedListBox();
            control.CheckOnClick = true;
            control.Width += 30;
            foreach (CodeGenerationEvent ef in enumFields)
            {
                if (ef == CodeGenerationEvent.None)
                    continue;
                bool isChecked = (e & ef) == ef;
                control.Items.Add( ef, isChecked);
            }
            service.DropDownControl(control);
            CodeGenerationEvent result = CodeGenerationEvent.None;
            foreach (CodeGenerationEvent chk in control.CheckedItems)
            {
                result |= chk;
            }
            return result;
        }

 

 


    }
}
